﻿using System;
using System.Collections.ObjectModel;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;

namespace com.IronOne.BoardPACWinAppBO.Agenda
{
    public class AgendaItem : ObservableObject
    {
        public delegate void AgendaItemClickBgChangeDel(AgendaItem agendaItem);

        public delegate void CloseAgendaPresenterDel(AgendaItem agendaItem);

        /// <summary>
        ///     The <see cref="PresenterVisibility" /> property's name.
        /// </summary>
        public const string PresenterVisibilityPropertyName = "PresenterVisibility";

        //public string DownloadStatusIconPath { get; set; }
        /// <summary>
        ///     The <see cref="DownloadStatusIconPath" /> property's name.
        /// </summary>
        public const string DownloadStatusIconPathPropertyName = "DownloadStatusIconPath";

        /// <summary>
        ///     The <see cref="PresenterName" /> property's name.
        /// </summary>
        public const string PresenterNamePropertyName = "PresenterName";

        /// <summary>
        ///     The <see cref="ItemStatus" /> property's name.
        /// </summary>
        public const string ItemStatusPropertyName = "ItemStatus";

        /// <summary>
        ///     The <see cref="DownloadStatus" /> property's name.
        /// </summary>
        public const string DownloadStatusPropertyName = "DownloadStatus";

        /// <summary>
        ///     The <see cref="PresenterCloseBtnVisibility" /> property's name.
        /// </summary>
        public const string PresenterCloseBtnVisibilityPropertyName = "PresenterCloseBtnVisibility";

        /// <summary>
        ///     The <see cref="MeetingStatusSideIconBgColor" /> property's name.
        /// </summary>
        public const string MeetingStatusSideIconBgColorPropertyName = "MeetingStatusSideIconBgColor";

        /// <summary>
        ///     The <see cref="AgendaItemDefaultBg" /> property's name.
        /// </summary>
        public const string AgendaItemDefaultBgPropertyName = "AgendaItemDefaultBg";

        /// <summary>
        ///     The <see cref="MeetingStatusSideIconVisibility" /> property's name.
        /// </summary>
        public const string MeetingStatusSideIconVisibilityPropertyName = "MeetingStatusSideIconVisibility";

        //public string PaperDescription { get; set; }
        /// <summary>
        ///     The <see cref="PaperDescription" /> property's name.
        /// </summary>
        public const string PaperDescriptionPropertyName = "PaperDescription";

        //public static event AgendaItemClickBgChangeDel AgendaItemClickBgChangeEvt;

        public static EventHandler AgendaItemClickBgEvtHandler;
        private RelayCommand<object> _agendaItemClickCommand;
        private string _agendaItemDefaultBg = "#FFF2FBFF";
        private RelayCommand<object> _agendaPresenterCloseCommand;
        private int _downloadStatus;
        private string _downloadStatusIconPath = "";
        private string _itemStatus;
        private string _meetingStatusSideIconBgColor = "Transparent";
        private Visibility _meetingStatusSideIconVisibility = Visibility.Visible;
        private string _paperDescription = "";
        private Visibility _presenterCloseBtnVisibility;
        private string _presenterName;
        private Visibility _presenterVisibility;

        public AgendaItem()
        {
            var sb = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
            AgendaItemNameColor = sb;
        }

        public string PaperItemBgColor { get; set; }
        public string CommentsCountDisplay { get; set; }
        public int ItemWidth { get; set; }
        public int CellColorR { get; set; }
        public int CellColorG { get; set; }
        public int CellColorB { get; set; }
        public byte UserApprovalStatus { get; set; }
        public string DocTypeIconPath { get; set; }
        public string MemberDecisionStatusDisplay { get; set; }
        public string MemberDecisionStatusToView { get; set; }
        public string PaperRefNoDisplay { get; set; }
        public string MeetingStatusIconSource { get; set; }

        /// <summary>
        /// The <see cref="AnnotateVersion" /> property's name.
        /// </summary>
        public const string AnnotateVersionPropertyName = "AnnotateVersion";

        private string _annotateVersion = "";

        /// <summary>
        /// Sets and gets the AnnotateVersion property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public string AnnotateVersion
        {
            get
            {
                return _annotateVersion;
            }

            set
            {
                if (_annotateVersion == value)
                {
                    return;
                }

                _annotateVersion = value;
                RaisePropertyChanged(AnnotateVersionPropertyName);
            }
        }

        public Visibility PresenterVisibility
        {
            get { return _presenterVisibility; }

            set
            {
                if (_presenterVisibility == value)
                {
                    return;
                }

                _presenterVisibility = value;
                RaisePropertyChanged(PresenterVisibilityPropertyName);
            }
        }

        /// <summary>
        ///     Sets and gets the DownloadStatusIconPath property.
        ///     Changes to that property's value raise the PropertyChanged event.
        /// </summary>
        public string DownloadStatusIconPath
        {
            get { return _downloadStatusIconPath; }

            set
            {
                if (_downloadStatusIconPath == value)
                {
                    return;
                }

                _downloadStatusIconPath = value;
                RaisePropertyChanged(DownloadStatusIconPathPropertyName);
            }
        }

        public int SelectedPaperId { get; set; }
        public int MeetingId { get; set; }
        public int VersionId { get; set; }

        public string PresenterName
        {
            get { return _presenterName; }

            set
            {
                if (_presenterName == value)
                {
                    return;
                }

                _presenterName = value;
                RaisePropertyChanged(PresenterNamePropertyName);
            }
        }

        public string StartTime { get; set; }
        public string EndTime { get; set; }

        public string ItemStatus
        {
            get { return _itemStatus; }

            set
            {
                if (_itemStatus == value)
                {
                    return;
                }

                _itemStatus = value;
                RaisePropertyChanged(ItemStatusPropertyName);
            }
        }

        public int DownloadStatus
        {
            get { return _downloadStatus; }

            set
            {
                if (_downloadStatus == value)
                {
                    return;
                }

                _downloadStatus = value;
                RaisePropertyChanged(DownloadStatusPropertyName);
            }
        }

        public Visibility PresenterCloseBtnVisibility
        {
            get { return _presenterCloseBtnVisibility; }

            set
            {
                if (_presenterCloseBtnVisibility == value)
                {
                    return;
                }

                _presenterCloseBtnVisibility = value;
                RaisePropertyChanged(PresenterCloseBtnVisibilityPropertyName);
            }
        }

        /// <summary>
        ///     Gets the AgendaPresenterCloseCommand.
        /// </summary>
        public RelayCommand<object> AgendaPresenterCloseCommand
        {
            get
            {
                return _agendaPresenterCloseCommand
                       ?? (_agendaPresenterCloseCommand = new RelayCommand<object>(
                           SelectedAgendaItem =>
                           {
                               CloseAgendaPresenterEvt((AgendaItem) SelectedAgendaItem);
                                   //This will hit treepageviewmodel method.
                           }));
            }
        }

        /// <summary>
        ///     Gets the AgendaItemClickCommand.
        /// </summary>
        public RelayCommand<object> AgendaItemClickCommand
        {
            get
            {
                return _agendaItemClickCommand
                       ?? (_agendaItemClickCommand = new RelayCommand<object>(
                           SelectedAgendaItem =>
                           {
                               //AgendaItemClickBgChangeEvt((AgendaItem)SelectedAgendaItem);
                               AgendaItemClickBgEvtHandler((AgendaItem) SelectedAgendaItem, EventArgs.Empty);
                           }));
            }
        }

        /// <summary>
        ///     Sets and gets the MeetingStatusSideIconBgColor property.
        ///     Changes to that property's value raise the PropertyChanged event.
        /// </summary>
        public string MeetingStatusSideIconBgColor
        {
            get { return _meetingStatusSideIconBgColor; }

            set
            {
                if (_meetingStatusSideIconBgColor == value)
                {
                    return;
                }

                _meetingStatusSideIconBgColor = value;
                RaisePropertyChanged(MeetingStatusSideIconBgColorPropertyName);
            }
        }

        /// <summary>
        ///     Sets and gets the AgendaItemDefaultBg property.
        ///     Changes to that property's value raise the PropertyChanged event.
        /// </summary>
        public string AgendaItemDefaultBg
        {
            get { return _agendaItemDefaultBg; }

            set
            {
                if (_agendaItemDefaultBg == value)
                {
                    return;
                }

                _agendaItemDefaultBg = value;
                RaisePropertyChanged(AgendaItemDefaultBgPropertyName);
            }
        }

        /// <summary>
        ///     Sets and gets the MeetingStatusSideIconOpacity property.
        ///     Changes to that property's value raise the PropertyChanged event.
        /// </summary>
        public Visibility MeetingStatusSideIconVisibility
        {
            get { return _meetingStatusSideIconVisibility; }

            set
            {
                if (_meetingStatusSideIconVisibility == value)
                {
                    return;
                }

                _meetingStatusSideIconVisibility = value;
                RaisePropertyChanged(MeetingStatusSideIconVisibilityPropertyName);
            }
        }

        /// <summary>
        ///     Sets and gets the PaperDescription property.
        ///     Changes to that property's value raise the PropertyChanged event.
        /// </summary>
        public string PaperDescription
        {
            get { return _paperDescription; }

            set
            {
                if (_paperDescription == value)
                {
                    return;
                }

                _paperDescription = value;
                RaisePropertyChanged(PaperDescriptionPropertyName);
            }
        }

        public static event CloseAgendaPresenterDel CloseAgendaPresenterEvt;

        #region Properties

        //public int ID { get; set; }
        /// <summary>
        ///     The <see cref="Id" /> property's name.
        /// </summary>
        public const string IdPropertyName = "ID";

        private int _id;

        /// <summary>
        ///     Sets and gets the ID property.
        ///     Changes to that property's value raise the PropertyChanged event.
        /// </summary>
        public int Id
        {
            get { return _id; }

            set
            {
                if (_id == value)
                {
                    return;
                }

                _id = value;
                RaisePropertyChanged(IdPropertyName);
            }
        }

        public int? PreviousId { get; set; }
        public int Order { get; set; }
        public string Name { get; set; }

        // 0 - Heading, 1-Paper
        public byte HeadorPaper { get; set; }
        public Visibility IsHeading { get; set; }
        public Visibility IsPaper { get; set; }

        public byte? DocType { get; set; }
        public int? PaperStatus { get; set; }
        public string PaperRefNo { get; set; }
        public int DecisionStatus { get; set; }

        public bool IsPaperAvailable { get; set; }
        public int CommentsCount { get; set; }
        public Visibility IsCommentsAvailable { get; set; }
        public byte IsAllowed { get; set; }

        public byte NotificationStatus { get; set; }

        // public SolidColorBrush AgendaItemNameColor { get; set; }

        /// <summary>
        /// </summary>
        public const string AgendaItemNameColorPropertyName = "AgendaItemNameColor";

        private SolidColorBrush _agendaItemNameColor;

        public SolidColorBrush AgendaItemNameColor
        {
            get { return _agendaItemNameColor; }

            set
            {
                if (_agendaItemNameColor == value)
                {
                    return;
                }

                _agendaItemNameColor = value;
                RaisePropertyChanged(AgendaItemNameColorPropertyName);
            }
        }

        /// <summary>
        ///     The <see cref="IsFocused" /> property's name.
        /// </summary>
        public const string IsFocusedPropertyName = "IsFocused";

        private bool _isFocused;

        public bool IsFocused
        {
            get { return _isFocused; }

            set
            {
                //_isFocused = false;
                _isFocused = value;
                RaisePropertyChanged(IsFocusedPropertyName);
            }
        }

        #region Children

        private ObservableCollection<AgendaItem> _children = new ObservableCollection<AgendaItem>();

        /// <summary>
        ///     Gets or sets the child items.
        /// </summary>
        public ObservableCollection<AgendaItem> Children
        {
            get { return _children; }
            set
            {
                _children = value;
                RaisePropertyChanged("Children");
            }
        }

        #endregion

        #endregion
    }
}